﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefConsumableUsage" :model="stateConsumableUsage.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_RecordId_FormItem" prop="Entity.RecordId" :label="$t('message.autotrans._Model_ConsumableUsage_Record')">
            <el-select v-model="stateConsumableUsage.vmModel.Entity.RecordId" clearable>
               <el-option v-for="item in stateConsumableUsage.AllRecords" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MaterialId_FormItem" prop="Entity.MaterialId" :label="$t('message.autotrans._Model_ConsumableUsage_MaterialId')">
            <el-input v-model="stateConsumableUsage.vmModel.Entity.MaterialId" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MaterialName_FormItem" prop="Entity.MaterialName" :label="$t('message.autotrans._Model_ConsumableUsage_MaterialName')">
            <el-input v-model="stateConsumableUsage.vmModel.Entity.MaterialName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Specification_FormItem" prop="Entity.Specification" :label="$t('message.autotrans._Model_ConsumableUsage_Specification')">
            <el-input v-model="stateConsumableUsage.vmModel.Entity.Specification" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Quantity_FormItem" prop="Entity.Quantity" :label="$t('message.autotrans._Model_ConsumableUsage_Quantity')">
            <el-input v-model="stateConsumableUsage.vmModel.Entity.Quantity" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Unit_FormItem" prop="Entity.Unit" :label="$t('message.autotrans._Model_ConsumableUsage_Unit')">
            <el-input v-model="stateConsumableUsage.vmModel.Entity.Unit" clearable></el-input>
        </el-form-item>

        </el-col>
      </el-row>

      <div style="text-align:right;">
        <WtmButton @click="onSubmitConsumableUsage"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onCloseConsumableUsage"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageEquipmentManagementConsumableUsageCreate;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { consumableusageApi } from '/@/api/equipmentmanagement/consumableusage';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefConsumableUsage = ref();
const stateConsumableUsage = reactive({
    vmModel: {
	  Entity:{
        RecordId: null,
        MaterialId: null,
        MaterialName: '',
        Specification: '',
        Quantity: null,
        Unit: '',
      },

	},
    
    AllRecords: [] as any[],
});

// 取消
const onCloseConsumableUsage = () => {
    closeDialog();
};

// 提交
const onSubmitConsumableUsage = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefConsumableUsage.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            consumableusageApi().add(stateConsumableUsage.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/EquipmentManagement/ConsumableUsage/GetMaintenanceRecords',[],false).then(x=>{stateConsumableUsage.AllRecords = x});
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

